﻿using System;
using System.IO;

namespace MediaFS.Data
{
    public abstract class MemoryItem
    {
        MemoryFolder _parent;

        protected MemoryItem(MemoryFolder parent, string name)
        {
            Parent = parent;
            Name = name;
            CreationTime = DateTime.Now;
            LastAccessTime = DateTime.Now;
            LastWriteTime = DateTime.Now;
        }

        public MemoryFolder Parent
        {
            get
            {
                return _parent;
            }
            set
            {
                if (_parent == value) return;
                if (_parent != null)
                {
                    _parent.Children.Remove(this);
                }
                if (value != null)
                {
                    value.Children.Add(this);
                }

                _parent = value;
            }
        }

        public string Name { get; set; }
        public FileAttributes Attributes { get; set; }
        public DateTime LastAccessTime { get; set; }
        public DateTime LastWriteTime { get; set; }
        public DateTime CreationTime { get; set; }
        public string FullPath
        {
            get { return _parent == null ? Name : _parent.FullPath + "\\" + Name; }
        }

        public object Tag { get; set; }
    }
}
